package com.cx.utils;

import javafx.scene.control.TableRow;
import lombok.SneakyThrows;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: StringToDate
 * @Description:
 * @Author: cx
 * @Date: 2022/10/20 3:45
 **/
@Component
public class StringToDate implements Converter<String, Date> {

    @Override
    public Date convert(String String) {

        System.out.println("这个方法进来了嘛" );
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date returnDate = null;
        try {
            returnDate = simpleDateFormat.parse(String);
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("有异常为"+e);
            throw new RuntimeException("传过来得参数不能为空，或者日期格式不为yyyy-MM-dd");
        }
        return returnDate;
    }
}
